package _case

import "fmt"

// 泛型结构体
type MyStruct[T interface{ *int | *string }] struct {
	Name string
	Data T
}

// 泛型receiver
func (m MyStruct[T]) GetData() T {
	//var i interface{} = 10
	//c1,ok := i.(int) //断言
	//c2,ok2 := t.(T) //泛型不支持断言
	return m.Data
}

func RecevierCase() {
	data := 18
	myStruct := MyStruct[*int]{
		Name: "王旭东",
		Data: &data,
	}
	data1 := myStruct.GetData()
	fmt.Println(*data1, data1)

	str := "wangxudongniubi"
	myStruct1 := MyStruct[*string]{
		Name: "王旭东",
		Data: &str,
	}
	str1 := myStruct1.GetData()
	fmt.Println(*str1, str1)
}
